package com.bbs.model.controllers;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.bbs.model.dao.UserinfoMapper;
import com.bbs.model.entity.Admin;
import com.bbs.model.entity.Userinfo;
import com.bbs.model.services.AdminManageService;
import com.github.pagehelper.PageInfo;

@RestController
public class AdminManageController {

	@Autowired
	private AdminManageService as;
	
	@Autowired
	private UserinfoMapper um;

	public static final String CURRENT_USER = "CURRENTUSER";

	@RequestMapping("/adminlogin")
	public boolean dologin(Admin admin, HttpSession session) {
		Admin result = as.checklogin(admin);
		if (null != result) {
			session.setAttribute(CURRENT_USER, result);
			return true;
		} else {
			return false;
		}
	}

	@RequestMapping("/adminsearchuser")
	public PageInfo<Userinfo> doSearchUserinfo(Userinfo cond, int pageNum, int pageSize) {
		String username = cond.getUsername();
		if (username == null || (username.equals(""))) {
			cond = new Userinfo();
		}
		return as.searchUserinfo(cond, pageNum, pageSize);
	}
	
	/**
	 * 修改用户状态
	 * @param user
	 * @param way
	 */
	@RequestMapping("/adminmoduserstatus")
	public void doModuserstatus(Userinfo user,boolean way) {
		if(way==false) {
			as.moduserstatustofalse(user);
		}else {
			as.moduserstatustotrue(user);
		}
	}
}
